home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_Tix.idb / usr / freeware / lib / tix4.1 / demos / samples / Tree.tcl.z / Tree.tcl
Encoding:
Text File  |  1999-01-26  |  2.4 KB  |  88 lines

  1. # Tix Demostration Program
  2. #
  3. # This sample program is structured in such a way so that it can be
  4. # executed from the Tix demo program "widget": it must have a
  5. # procedure called "RunSample". It should also have the "if" statment
  6. # at the end of this file so that it can be run as a standalone
  7. # program using tixwish.
  8.  
  9. # This file demonstrates how to use the TixTree widget to display
  10. # hierachical data (A hypothetical DOS disk drive).
  11. #
  12.  
  13. proc RunSample {w} {
  14.  
  15.     # We create the frame and the ScrolledHList widget
  16.     # at the top of the dialog box
  17.     #
  18.     frame $w.top -relief raised -bd 1
  19.  
  20.     # Create a TixTree widget to display the hypothetical DOS disk drive
  21.     # 
  22.     #
  23.     tixTree $w.top.a -options {
  24.     separator "\\"
  25.     }
  26.  
  27.     pack $w.top.a -expand yes -fill both -padx 10 -pady 10 -side left
  28.  
  29.     set tree $w.top.a 
  30.     set hlist [$w.top.a subwidget hlist]
  31.  
  32.     # STEP (1) Add the directories into the TixTree widget (using the
  33.     #           hlist subwidget)
  34.  
  35.     set directories {
  36.     C:
  37.     C:\\Dos
  38.     C:\\Windows
  39.     C:\\Windows\\System
  40.     }
  41.  
  42.     foreach d $directories {
  43.     set text [lindex [split $d \\] end]
  44.     $hlist add $d -itemtype imagetext \
  45.         -text $text -image [tix getimage folder]
  46.     }
  47.  
  48.     # STEP (2) Use the "autosetmode" method of TixTree to indicate 
  49.     #           which entries can be opened or closed. The
  50.     #           "autosetmode" command will call the "setmode" method
  51.     #           to set the mode of each entry to the following:
  52.     #
  53.     #        "open" : the entry has some children and the children are
  54.     #             currently visible
  55.     #        "close": the entry has some children and the children are
  56.     #             currently INvisible
  57.     #        "none": the entry does not have children.
  58.     #
  59.     #    If you don't like the "autosetmode" method, you can always call
  60.     #    "setmode" yourself, but that takes more work.
  61.     
  62.     $tree autosetmode
  63.  
  64.     # Use a ButtonBox to hold the buttons.
  65.     #
  66.     tixButtonBox $w.box -orientation horizontal
  67.     $w.box add ok     -text Ok     -underline 0 -command "destroy $w" \
  68.     -width 6
  69.     $w.box add cancel -text Cancel -underline 0 -command "destroy $w" \
  70.     -width 6
  71.  
  72.     pack $w.box -side bottom -fill x
  73.     pack $w.top -side top -fill both -expand yes
  74. }
  75.  
  76.  
  77. # This "if" statement makes it possible to run this script file inside or
  78. # outside of the main demo program "widget".
  79. #
  80. if {![info exists tix_demo_running]} {
  81.     wm withdraw .
  82.     set w .demo
  83.     toplevel $w
  84.     RunSample $w
  85.     bind $w <Destroy> {if {"%W" == ".demo"} exit}
  86. }
  87.  
  88.